// 上传照片列表
<template>
    <li class="content-box">
        <div class="index-box">{{ isNaN(index)?defaultIndex + index + 1:index }}</div>
        <div class="right-box">
            <div class="right-box-top checks-box">
                <div class="code">
                    <span
                        style="color: #f15a5a; margin-right: 2px"
                        v-if="item.isMustUpload"
                    >*</span>
                    {{ item[props.name] }}
                    <span v-if="disabled&&item.attachments.length==0" class="noUpload">未上传</span>
                </div>
                <van-checkbox
                    v-if="item.allowNone == 1"
                    v-model="item.isNil"
                    shape="square"
                    @click="checkItem(index)"
                    >无此项</van-checkbox
                >
            </div>
            <div class="right-box-bottom">
                <div class="upload-box">
                    <qm-file-upload
                        :ref="`${listName}${index + 1}`"
                        :galleryOptions="{ multiple: true, maximum: 9 }"
                        :disabled="disabled"
                        extensions="jpg,jpeg,png"
                        accept=".jpg,.jpeg,.png"
                        :params="{
                            type: 'attach',
                            dataKey: dataKey,
                            bizType: bizType,
                            typeCode,
                            address,
                        }"
                        :showLegend="{show:item.templateAttachs!=null&&item.templateAttachs.length,id:item.templateAttachs!=null&&item.templateAttachs.length ? item.templateAttachs[0].attachmentId : ''}" 
                        :defaultFiles="item.attachments"
                        :showOffline="showOffline"
                        :isDefaultFile="isDefaultFile"
                        :uploadId="`${listName}${index + 1}`"
                        :actionsOneGroup="actionsGroup(item)"
                        :maximagescount="maximagescount"
                    >
                    </qm-file-upload>
                </div>
            </div>
        </div>
    </li>
</template>

<script>
import Config from '@/libs/config.js'
export default {
    name: 'v-picture-item',
    props: {
        index: {
            type: Number|String,
        },
        item: {
            type: Object,
            default: () => {},
        },
        typeCode: {
            type: String,
        },
        listName: {
            type: String,
        },
        dataKey: {
            type: String,
        },
        bizType: {
            type: String,
        },
        props: {
            type: Object,
            default: () => {
                return { name: 'name' }
            },
        },
        disabled: {
            type: Boolean,
        },
        isDefaultFile: {
            type: Boolean,
            default: false,
        },
        defaultIndex: {
            type: Number,
            default: 0,
        },
        address: {
            type: String,
            default: '',
        },
        // 上传方式的选择 1相册 2拍照 3文件
        actionsOneGroup: {
            type: Array,
            default: () => {
                return [1]
            },
        },
        maximagescount: {
            type: Number,
            default: 1
        },
        showOffline:{
            type:Boolean,
            default:false,
        }
    },
    data() {
        return {
            download: Config.api.download,
        }
    },
    methods: {
        actionsGroup(item){
            if(this.showOffline){
                return [1,2]
            }else{
                return item.uploadFrom?item.uploadFrom.split(','):this.actionsOneGroup
            }
        },
        checkItem(index) {
            this.$emit('check', this.listName, index)
        },
        getUploadedCount() {
            return this.$refs[`${this.listName}${this.index + 1}`].getUploadedCount()
        },
    },
}
</script>

<style lang="less" scoped>
@import url('../../assets/css/commonPage.less');

@{deep}.accordion .accordion-item > .item-link > .item-content {
    padding-left: 16px !important;
}
li {
    &.content-box {
        padding: 0;
        margin: 0;
        background: transparent !important;
        box-shadow: none;
    }
    &:first-child .content-box {
        margin-top: 0;
    }

    .content-box {
        background: #fff;
        margin-bottom: 0;
        padding: 10px 0;
        align-items: flex-start;
    }

    .index-box {
        background: rgba(51, 133, 255, 0.1);
        border-radius: 1px;
        font-size: 13px;
        color: #1990ff;
        width: 25px;
        height: 22px;
        text-align: center;
        line-height: 22px;
    }

    .right-box {
        margin-left: 10px;
        font-size: 14px;
        color: #333;
    }

    .checks-box {
        display: flex;
        align-items: flex-start;
        justify-content: space-between;

        .code {
            flex: 1;
            margin-bottom: 10px;
            display: flex;
            span{
                flex-shrink: 0;
                height: 16px;
                line-height: 16px;
            }
        }
    }
    /deep/.pic_upload {
        padding: 0;
        margin: 0;
    }
}
.noUpload{
    background: #f7f8fa;
    color: #b7c2d9;
    border: 1px solid #b7c2d9;
    border-radius: 6px;
    border-bottom-left-radius: 0;
    padding: 2px 5px;
    font-size: 12px;
    margin-left: 5px;
}
</style>
